package com.carleasoft.mps.forum.business.answer.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.forum.annotation.OpenApi;
import com.carleasoft.mps.forum.business.answer.bean.ForumData;
import com.carleasoft.mps.forum.business.answer.bean.po.ForumDataPo;
import com.carleasoft.mps.forum.business.answer.bean.po.ForumUserPo;
import com.carleasoft.mps.forum.business.answer.bean.vo.ForumUserVo;
import com.carleasoft.mps.forum.business.answer.service.ForumDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zang
 * @since 2023-05-09
 */
@RestController
@RequestMapping("/forumData")
public class ForumDataController {
    @Autowired
    private ForumDataService forumDataService;
    /**
     * @author zang
     * @desc 分页查询帖子
     * @date 2023-05-19
     */
    @PostMapping("/pageForumData")
    public R pageForumData(@RequestBody ForumDataPo forumDataPo) {
        Page page = new Page(forumDataPo.getCurrent(), forumDataPo.getSize());
        Page<ForumData> res = forumDataService.pageForumData(page,forumDataPo);
        return R.ok(res);
    }
    @PostMapping("/bisPageForumData")
    public R bisPageForumData(@RequestBody ForumDataPo forumDataPo) {
        forumDataPo.setBisUserCode(ThreadUserContext.getCurrentCacheUser().getUserCode());
        Page page = new Page(forumDataPo.getCurrent(), forumDataPo.getSize());
        Page<ForumData> res = forumDataService.bisPageForumData(page,forumDataPo);
        return R.ok(res);
    }
    /**
     * @author zang
     * @desc 保存帖子
     * @date 2023-05-19
     */
    @PostMapping("/saveForumData")
    public R saveForumData(@RequestBody ForumData forumData, HttpServletRequest request) {
        String s = forumDataService.saveForumData(forumData, request);
        if(s.equals("提交成功")) {
            return R.ok();
        } else {
            return R.failed("000001",s);
        }
    }
    /**
     * @author zang
     * @desc 批量删除帖子接口（逻辑删除 ）
     * @date 2023-05-19
     */
    @PostMapping("/deleteForumData")
    public R deleteForumData(@RequestBody ForumDataPo forumDataPo, HttpServletRequest request) {
        forumDataService.deleteForumData(forumDataPo);
        return R.ok();
    }
    /**
     * @author zang
     * @desc 批量同意
     * @date 2023-05-19
     */
    @PostMapping("/passForumData")
    public R passForumData(@RequestBody ForumDataPo forumDataPo, HttpServletRequest request) {
        forumDataService.passForumData(forumDataPo);
        return R.ok();
    }
    /**
     * @author zang
     * @desc 批量拒绝
     * @date 2023-05-19
     */
    @PostMapping("/failForumData")
    public R failForumData(@RequestBody ForumDataPo forumDataPo, HttpServletRequest request) {
        forumDataService.failForumData(forumDataPo);
        return R.ok();
    }
    
    /**
     * @author zang
     * @desc 帖子详情
     * @date 2023-05-19
     */
    @PostMapping("/detailForumData")
    public R detailForumData(@RequestBody ForumDataPo forumDataPo, HttpServletRequest request) {
        ForumData forumData = forumDataService.detailForumData(forumDataPo);
        return R.ok(forumData);
    }

    /**
     * @author zang
     * @desc 获取推荐标签
     * @date 2023-05-19
     */
    @PostMapping("/selForumTab")
    public R selForumTab(@RequestBody ForumDataPo forumDataPo) {
        Page page = new Page(forumDataPo.getCurrent(), forumDataPo.getSize());
        Page<ForumData> res = forumDataService.selForumTab(page,forumDataPo);
        return R.ok(res);
    }
    /**
     * @author zang
     * @desc 获取当前用户的统计数
     * @date 2023-06-16
     */
    @PostMapping("/selForumUser")
    public R selForumUser(@RequestBody ForumUserPo forumUserPo) {
        ForumUserVo res = forumDataService.selForumUser(forumUserPo);
        return R.ok(res);
    }

}

